<template>
	<view class="businesscenter">
		<u-mask v-show="maskShow" class="u-mask" :show="maskShow"  :mask-click-able="false">
			<u-modal class="u-modal" v-model="show" :content="content" width="450" 
			confirm-text="重新提交" @confirm="getfirstlogin" confirm-color="#731400"></u-modal>
		</u-mask>
		<!-- <h3>商家中心</h3> -->
		<view class="header">
			<view class="h-box">
				<image :src="imgUrl" mode="aspectFit"></image>
				<view class="name-box">
					<p @click="goLogin">Hi, {{name}}</p>
					<view class="b-box">
						<image src="../../static/images/renzheng.png" mode=""></image>
						<text @click="getFirstlogin">{{nametext}}</text>
					</view>
				</view>
			</view>
			<button @click="businessData" v-show="shanghuShow">商铺信息</button>
		</view>
		<view class="middle">
			<p>优惠券管理</p>
			<view class="img-box">
				<image src="../../static/images/faxing.png" mode="aspectFit" @click="getfxlist"></image>
				<image src="../../static/images/linqu.png" mode="aspectFit" @click="getreceivecoupons"></image>
				<image src="../../static/images/hexiao.png" mode="aspectFit" @click="getcouponspin"></image>
			</view>
		</view>
		<view class="footer">
			<p>数据统计</p>
			<view class="item-box" v-for="(item,index) in statisticsList" :key="index">
				<view class="item">
					<p>{{item.type_total_num}}</p>
					<p>总发券品类</p>
				</view>
				<view class="item">
					<p>{{item.all_total_num}}</p>
					<p>总发券数量</p>
				</view>
				<view class="item">
					<p>{{item.off_total_num}}</p>
					<p>总使用数量</p>
				</view>
				<view class="item">
					<p>{{item.today_sale_num}}</p>
					<p>今日销售</p>
				</view>
				<view class="item">
					<p>{{item.today_receive_num}}</p>
					<p>今日领取</p>
				</view>
				<view class="item">
					<p>{{item.today_off_num}}</p>
					<p>今日使用</p>
				</view>
				<view class="item">
					<p>{{item.month_sale_num}}</p>
					<p>本月销售</p>
				</view>
				<view class="item">
					<p>{{item.month_receive_num}}</p>
					<p>本月领取</p>
				</view>
				<view class="item">
					<p>{{item.month_off_num}}</p>
					<p>本月使用</p>
				</view>
			</view>
		</view>
		<view class="bottom">
			<image src="../../static/images/bottomlogo.png" mode="aspectFit"></image>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {shareMixins} from '../../mixins/share.js'
	export default {
		mixins:[shareMixins],
		data() {
			return {
				shareData: {
				    title: '空港卡券联盟商户端',
				    path: '/pages/mine/mine' // 分享的页面路径
				},
				shanghuShow:false,
				nametext:'未认证',
				name:'点击登录',
				imgUrl:'../../static/tabbar-image/sjzx.png',
				show:true,
				content: '审核未通过',
				maskShow:false,//是否显示蒙层
				statisticsList:[]
			}
		},
		onShow() {
			this.statisticsList.length = 0
			this.getCouponStatistics()
		},
		onLoad() {
			var loginuserinfo = uni.getStorageSync('loginuserInfo')
			this.name = loginuserinfo.nickName
			this.imgUrl = loginuserinfo.avatarUrl
			this.getBusinessInfo()
		},
		methods: {
			goLogin(){
				if(this.name === '点击登录' || this.name == undefined){
					uni.redirectTo({
						url:'../login/login'
					})
				}else{
					console.log('已登录')
				}
			},
			getFirstlogin(){
				if(this.nametext == '未认证' && this.name != undefined){
					uni.redirectTo({
						url:'../firstlogin/firstlogin'
					})
				}else if(this.nametext == '未认证' && this.name == undefined){
					this.$refs.uToast.show({
						title:'请先登录',
						type:'warning'
					})
					setTimeout(() => {
						uni.redirectTo({
							url:'../login/login'
						})
					},1000)
				}
			},
			async getBusinessInfo(){//获取商户信息
				const res = await this.$myRequest({
					url:'/api/businessBasic/getBusinessInformationData'
				}).then((res) => {
					uni.setStorageSync('shanghuData',res.data.data)
					if(res.data.data.status === 0){
						this.nametext = '待审核'
						this.maskShow = true
						this.content = '等待审核中...'
					}else if(res.data.data.status === -1){
						this.nametext = '未通过'
						this.maskShow = true
						this.content = '审核未通过'
					}else if(res.data.data.status === 1){
						this.nametext = '认证商家'
						this.shanghuShow = true
						// console.log(this.nametext)
					}
				})
			},
			async getCouponStatistics(){//获取商户数据统计
				const res = await this.$myRequest({
					url:'/api/businessBasic/getCouponStatistics'
				}).then((res) => {
					this.statisticsList.push(res.data.data)
				})
			},
			getfirstlogin(){
				uni.redirectTo({
					url: '../firstlogin/firstlogin'
				});
			},
			getfxlist(){//跳转发行优惠券
				if(this.name === '点击登录' || this.name == undefined){
					this.$refs.uToast.show({
						title:'请先登录',
						type:'warning'
					})
					setTimeout(() => {
						uni.redirectTo({
							url:'../login/login'
						})
					},1000)
				}else if(this.nametext == '未认证'){
					this.$refs.uToast.show({
						title:'请先认证',
						type:'warning'
					})
					setTimeout(() => {
						uni.redirectTo({
							url:'../firstlogin/firstlogin'
						})
					},1500)
				}else{
					uni.navigateTo({
						url:'../../cardVoucher/pages/Issuecoupons/Issuecoupons'
					})
				}
				
			},
			getreceivecoupons(){//跳转已领取优惠券
				if(this.name === '点击登录' || this.name == undefined){
					this.$refs.uToast.show({
						title:'请先登录',
						type:'warning'
					})
					setTimeout(() => {
						uni.redirectTo({
							url:'../login/login'
						})
					},1500)
				}else if(this.nametext == '未认证'){
					this.$refs.uToast.show({
						title:'请先认证',
						type:'warning'
					})
					setTimeout(() => {
						uni.redirectTo({
							url:'../firstlogin/firstlogin'
						})
					},1500)
				}else{
					uni.navigateTo({
						url:'../../cardVoucher/pages/receivecoupons/receivecoupons'
					})
				}
			},
			getcouponspin(){//跳转核销优惠券
				if(this.name === '点击登录' || this.name == undefined){
					this.$refs.uToast.show({
						title:'请先登录',
						type:'warning'
					})
					setTimeout(() => {
						uni.redirectTo({
							url:'../login/login'
						})
					},1500)
				}else if(this.nametext == '未认证'){
					this.$refs.uToast.show({
						title:'请先认证',
						type:'warning'
					})
					setTimeout(() => {
						uni.redirectTo({
							url:'../firstlogin/firstlogin'
						})
					},1500)
				}else{
					uni.navigateTo({
						url:'../../cardVoucher/pages/couponspin/couponspin'
					})
				}
			},
			businessData(){//跳转商户信息
			console.log(11)
				uni.navigateTo({
					url:'../../cardVoucher/pages/businessData/businessData'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.businesscenter{
		.u-mask{
			position: relative;
			.rect {
				border-radius: 50rpx;
				font-weight: bold;
				position: absolute;
				top: 50%;
				margin-top: -40rpx;
				left: 50%;
				margin-left: -100rpx;
				width: 200rpx;
				height: 80rpx;
				background-color: #fff;
				text-align: center;
				line-height: 80rpx;
				
			}
		}
		
		.header{
			z-index: 1;
			width: 100%;
			height: 500rpx;
			background-image: url();
			background-size: cover;
			margin-top: -70rpx;
			display: flex;
			align-items: center;
			button{
				border-radius: 25rpx;
				color: #FFFFFF;
				background: linear-gradient(#FAA174,#ED6636);
				font-size: 28rpx;
				margin-right: 30rpx;
				height: 40rpx;
				width: 140rpx;
				padding: 0;
				line-height: 40rpx;
			}
			.h-box{
				display: flex;
				align-items: center;
				justify-content: flex-start;
				image{
					width: 128rpx;
					height: 128rpx;
					margin-right: 20rpx;
					margin-left: 32rpx;
					border-radius: 50%;
				}
				.name-box{
					p{
						color: #731400;
						font-size: 40rpx;
					}
					.b-box{
						width: 160rpx;
						display: flex;
						align-items: center;
						justify-content: flex-start;
						border-radius: 16rpx;
						background: linear-gradient(#F8D45C,#F09135);
						image{
							width: 28rpx;
							height: 32rpx;
							// background: linear-gradient(#FFEED9,#FFE7CB,#FFDDB9);
							margin-right: 8rpx;
							margin-left: 0;
						}
						text{
							color: #FFFFFF;
							font-size: 22ropx;
						}
					}
				}
			}
		}
		.middle{
			padding: 32rpx 32rpx 40rpx 32rpx;
			background-color: #FFFFFF;
			border-radius: 40rpx 40rpx 0 0;
			z-index: 99;
			margin-top: -74rpx;
			p{
				font-size: 34rpx;
				font-weight: bold;
				color: #3C3C3C;
				margin-bottom: 20rpx;
			}
			.img-box{
				display: flex;
				justify-content: space-between;
				image{
					width: 214rpx;
					height: 296rpx;
				}
			}
		}
		.footer{
			margin-top: 20rpx;
			background-color: #FFFFFF;
			p{
				// margin-left:36rpx;
				font-size: 34rpx;
				font-weight: bold;
				padding: 36rpx;
				border-bottom: 1px solid #F6F6F7;
			}
			.item-box{
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				.item{
					text-align: center;
					width: 251rpx;
					height: 200rpx;
					border: 1px solid #F6F6F7;
					p{
						border: none;
						margin: 0;
						padding: 0;
					}
					p:nth-child(1){
						margin-top: 38rpx;
						margin-bottom: 18rpx;
						color: #731400;
						font-size: 36rpx;
						font-weight: bold;
					}
					p:nth-child(2){
						margin-bottom: 40rpx;
						color: #8B8B8B;
						font-size: 28rpx;
					}
				}
			}
			
		}
		.bottom{
			background-color: #FFFFFF;
			padding-top: 92rpx;
			padding-bottom: 58rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			image{
				width: 113rpx;
				height: 64rpx;
			}
		}
	}
	
</style>
